package week11;

public class ArrayUtil {
	public static int[] generateIntArr(int size){
		int[] arr = new int[size];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = (int) (Math.random()*Integer.MAX_VALUE);
		}
		return arr;
	}
	
	public static int findMax(int[] arr){
			return ArrayUtil.findMax(arr,0,arr.length-1);
	}
	
	public static int findMax(int[] arr,int begin,int end){
		int max = arr[0];
		for (int i = begin; i < end; i++) {
			if (max<arr[i]) {
				max = arr[i];
			}
		}
		return max;
		
	}
	
    /*将范围存储在数组中，假设有45个数，那么范围是0,10,20,30,40,45*/
	public static int[] generateRange(int length,int n){
		int step  = length/n;
		int[] arr = new int[n+1];
		for (int i = 0; i < arr.length; i++) {
			if(i==arr.length-1)
				arr[i] = length;
			else
				arr[i] = i*step;
		}
		return arr;
	}
}
